﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Swing_Card.aspx.cs" Inherits="JKF.Web.Customer.Swing_Card.Swing_Card" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <%= RegScript("~/js/jquery.1.5.js")%>
    <%=RegScript("~/js/Common.js")%>
    <%=RegScript("~/js/jquery.json.js")%>
    <%=RegScript("~/js/jquery.nhis.js")%>
    <%=RegScript("~/js/jquery.rchis.js")%>
    <%=RegScript("~/js/jquery.validate.js")%>
    <%=RegScript("~/js/DatePicker/WdatePicker.js")%>
    <%=RegStyle("~/js/suggest/jquery.suggest.css")%>
    <%=this.RegStyle("~/App_Themes/Theme2/Include.css")%>
    <style type="text/css">
        body { height: auto; }
    </style>
    <script type="text/javascript">
        var appPath = "<%=AppPath %>";
        var areaHandler = appPath + '/do/Dic/Dic_Area.do';
        var curstomerHandler = appPath + '/do/Customer/Customer.do';
        $(function () {
            $("#NEW_CARD_NO").InitUniqueCode($.FxNull($("#OLD_CARD_NO").val(), ""));
            $("#NEW_CARD_NO").UniqueCode(function () {
                var cardNo = $.FxNull($("#CARD_NO").val(), "");
                var curKey = $("#CURSTOMER_KEY").val();
                $.post(curstomerHandler, { ActionName: "CardNoExists", cardNo: cardNo, customerKey: curKey },
                    function (rslt) {
                        if (rslt.Success) {
                            $("#NEW_CARD_NO").attr("state", rslt.Data ? "2" : "0");
                            $.validateAll();
                            return;
                        }
                        alert(rslt.Message);
                    }, "json");
            }, false);
            alxVr.push({
                id: "NEW_CARD_NO",
                rule: function (cn) {
                    var vl = $.trim(cn.val());
                    if (vl == "") return true;
                    if (vl.length != 8) {
                        this.msg = "顾客卡号应在8个字符之内.";
                        return false;
                    }
                    var state = cn.attr("state");
                    if (state == "0") {
                        CheckCardNo();
                        return true;
                    }
                    else if (state == "1") {
                        this.msg = "顾客卡号已存在.";
                        return false;
                    }
                    return true;
                }
            });
            alxVr.push({
                id: "LEVEL_CODE",
                rule: function (cn) {
                    var vl = $.trim(cn.val());
                    if (vl == "") {
                        this.msg = "请选择顾客级别.";
                        return false;
                    }
                    return true;
                }
            });
            $.validateBind();
            $("#btnSure").click(ChangeCardNo);
        });
        function CheckCardNo() {
            if ($("#NEW_CARD_NO").attr("state") == "0") {
                $.post(curstomerHandler, { ActionName: "CardNoExists", cardNo: $.trim($("#NEW_CARD_NO").val()) }, function (rslt) {
                    if (rslt.Success) {
                        $("#NEW_CARD_NO").attr("state", rslt.Data ? "1" : "2");
                        if (rslt.Data && window.fmSubmit) ChangeCardNo();
                        return;
                    }
                    alert(rslt.Message);
                }, "json");
                return false;
            }
            return true;
        }

        window.fmSubmit = false;

        function ChangeCardNo() {
            window.fmSubmit = true;
            if (!CheckCardNo()) return;
            if (!$.validateAll()) {
                if ($(".alxv-failed").size() > 0) {
                    $(document).scrollTop($(".alxv-failed").eq(0).scrollTop());
                }
                return;
            };
            $.post(curstomerHandler, { ActionName: "ChangeCardNo", cardNo: $.trim($("#NEW_CARD_NO").val()), customerKey: $.trim($("#CURSTOMER_KEY").val()), levelCode: $.trim($("#LEVEL_CODE").val(), "") }, function (rslt) {
                if (rslt.Success) {
                    $("#OLD_CARD_NO").val(rslt.Data.CardNo);
                    $("#LEVEL_CODE").val(rslt.Data.LevelCode);
                    $("#NEW_CARD_NO").val("").attr("state", "0");
                    alert("操作成功.");
                    return;
                }
                alert(rslt.Message);
            }, "json");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="pop_logging_body">
            <table width="100%" class="common_table_noborde">
                <tr>
                    <td width="18%" align="right">旧卡号：<input type="hidden" id="CURSTOMER_KEY" value="<%=CustomerKey%>" state="0" />
                    </td>
                    <td>
                        <input type="text" id="OLD_CARD_NO" value="<%=CurstomerCardNo%>" disabled="disabled" class="common_search_input w150" />
                    </td>
                </tr>
                <tr>
                    <td width="18%" align="right">新卡号：
                    </td>
                    <td>
                        <input type="text" id="NEW_CARD_NO" value="" state="0" class="common_search_input w150" />
                        <span class="f12red">注：如还使用原来卡号，则不需输新卡号</span>
                    </td>
                </tr>
                <tr>
                    <td width="18%" align="right">顾客级别：</td>
                    <td>
                        <select id="LEVEL_CODE" class="common_search_select w150">
                            <option value="">请选择</option>
                            <%=CustomerLevelOption %>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" id="btnSure" value="" class="common_btn_save mr30 mb25" />
                        <input type="button" value="" class="common_btn_remove mb25" onclick="top.tipsWindown.close();" /></td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>
